import api from '@/utils/api';

// 库存概览
export function getInventoryOverview() {
  return api({
    url: '/inventory/overview',
    method: 'get'
  }).then(response => response.data);
}

// 获取单个商品的库存详情
export function getProductInventory(id) {
  return api({
    url: `/inventory/product/${id}`,
    method: 'get'
  }).then(response => response.data);
}

// 更新商品库存信息
export function updateProductInventory(id, data) {
  return api({
    url: `/inventory/product/${id}`,
    method: 'put',
    data
  }).then(response => response.data);
}

// 库存调整
export function adjustInventory(data) {
  return api({
    url: '/inventory/adjust',
    method: 'post',
    data
  }).then(response => response.data);
}

// 获取库存预警商品
export function getWarningInventory() {
  return api({
    url: '/inventory/warning',
    method: 'get'
  }).then(response => response.data);
}

// 获取库存变动记录
export function getInventoryMovements(params) {
  return api({
    url: '/inventory/movements',
    method: 'get',
    params
  }).then(response => response.data);
}

// 仓库相关API
export function getAllWarehouses() {
  return api({
    url: '/inventory/warehouses',
    method: 'get'
  }).then(response => response.data);
}

export function getWarehouseById(id) {
  return api({
    url: `/inventory/warehouses/${id}`,
    method: 'get'
  }).then(response => response.data);
}

export function createWarehouse(data) {
  return api({
    url: '/inventory/warehouses',
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateWarehouse(id, data) {
  return api({
    url: `/inventory/warehouses/${id}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteWarehouse(id) {
  return api({
    url: `/inventory/warehouses/${id}`,
    method: 'delete'
  }).then(response => response.data);
}

export function getWarehouseInventory(id) {
  return api({
    url: `/inventory/warehouses/${id}/inventory`,
    method: 'get'
  }).then(response => response.data);
}

// 供应商相关API
export function getAllSuppliers() {
  return api({
    url: '/inventory/suppliers',
    method: 'get'
  }).then(response => response.data);
}

export function getSupplierById(id) {
  return api({
    url: `/inventory/suppliers/${id}`,
    method: 'get'
  }).then(response => response.data);
}

export function createSupplier(data) {
  return api({
    url: '/inventory/suppliers',
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateSupplier(id, data) {
  return api({
    url: `/inventory/suppliers/${id}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteSupplier(id) {
  return api({
    url: `/inventory/suppliers/${id}`,
    method: 'delete'
  }).then(response => response.data);
}

export function getSupplierStockInOrders(id) {
  return api({
    url: `/inventory/suppliers/${id}/stock-in`,
    method: 'get'
  }).then(response => response.data);
}

// 入库单相关API
export function getStockInOrders(params) {
  return api({
    url: '/inventory/stock-in',
    method: 'get',
    params
  }).then(response => response.data);
}

export function getStockInOrderById(id) {
  return api({
    url: `/inventory/stock-in/${id}`,
    method: 'get'
  }).then(response => response.data);
}

export function createStockInOrder(data) {
  return api({
    url: '/inventory/stock-in',
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateStockInOrder(id, data) {
  return api({
    url: `/inventory/stock-in/${id}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteStockInOrder(id) {
  return api({
    url: `/inventory/stock-in/${id}`,
    method: 'delete'
  }).then(response => response.data);
}

export function confirmStockInOrder(id) {
  return api({
    url: `/inventory/stock-in/${id}/confirm`,
    method: 'post'
  }).then(response => response.data);
}

export function cancelStockInOrder(id) {
  return api({
    url: `/inventory/stock-in/${id}/cancel`,
    method: 'post'
  }).then(response => response.data);
}

// 入库单明细相关API
export function addStockInItem(stockInId, data) {
  return api({
    url: `/inventory/stock-in/${stockInId}/items`,
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateStockInItem(stockInId, itemId, data) {
  return api({
    url: `/inventory/stock-in/${stockInId}/items/${itemId}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteStockInItem(stockInId, itemId) {
  return api({
    url: `/inventory/stock-in/${stockInId}/items/${itemId}`,
    method: 'delete'
  }).then(response => response.data);
}

// 出库单相关API
export function getStockOutOrders(params) {
  return api({
    url: '/inventory/stock-out',
    method: 'get',
    params
  }).then(response => response.data);
}

export function getStockOutOrderById(id) {
  return api({
    url: `/inventory/stock-out/${id}`,
    method: 'get'
  }).then(response => response.data);
}

export function createStockOutOrder(data) {
  return api({
    url: '/inventory/stock-out',
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateStockOutOrder(id, data) {
  return api({
    url: `/inventory/stock-out/${id}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteStockOutOrder(id) {
  return api({
    url: `/inventory/stock-out/${id}`,
    method: 'delete'
  }).then(response => response.data);
}

export function confirmStockOutOrder(id) {
  return api({
    url: `/inventory/stock-out/${id}/confirm`,
    method: 'post'
  }).then(response => response.data);
}

export function cancelStockOutOrder(id) {
  return api({
    url: `/inventory/stock-out/${id}/cancel`,
    method: 'post'
  }).then(response => response.data);
}

// 出库单明细相关API
export function addStockOutItem(stockOutId, data) {
  return api({
    url: `/inventory/stock-out/${stockOutId}/items`,
    method: 'post',
    data
  }).then(response => response.data);
}

export function updateStockOutItem(stockOutId, itemId, data) {
  return api({
    url: `/inventory/stock-out/${stockOutId}/items/${itemId}`,
    method: 'put',
    data
  }).then(response => response.data);
}

export function deleteStockOutItem(stockOutId, itemId) {
  return api({
    url: `/inventory/stock-out/${stockOutId}/items/${itemId}`,
    method: 'delete'
  }).then(response => response.data);
}

// 库存报表相关API
export function getInventoryStatusReport(params) {
  return api({
    url: '/inventory/reports/status',
    method: 'get',
    params
  }).then(response => response.data);
}

export function getInventoryMovementReport(params) {
  return api({
    url: '/inventory/reports/movement',
    method: 'get',
    params
  }).then(response => response.data);
}

export function getInventoryValueReport(params) {
  return api({
    url: '/inventory/reports/value',
    method: 'get',
    params
  }).then(response => response.data);
}

export function getInventoryTurnoverReport(params) {
  return api({
    url: '/inventory/reports/turnover',
    method: 'get',
    params
  }).then(response => response.data);
}

export function exportInventoryReport(type, params) {
  return api({
    url: `/inventory/reports/export/${type}`,
    method: 'get',
    params,
    responseType: 'blob'
  }).then(response => response.data);
} 